package es.abredatos.server;

import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

public class TutorialUtils {

	private static final int FETCH_MAX_RESULTS = 10;

	public static void insert(final String autor, final String tituloTutorial) {

		final PersistenceManager persistenceManager = PMF.get().getPersistenceManager();

		final Tutorial tutorial = new Tutorial(autor, tituloTutorial);
		persistenceManager.makePersistent(tutorial);
	}

	@SuppressWarnings("unchecked")
	public static List<Tutorial> getEntries() {
		final PersistenceManager persistenceManager = PMF.get().getPersistenceManager();

		final Query query = persistenceManager.newQuery(Tutorial.class);
		query.setOrdering("fecha DESC");
		query.setRange(0, FETCH_MAX_RESULTS);

		return (List<Tutorial>) query.execute();
	}
}
